package biz.ezcom.spring.ioc.test;

import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import biz.ezcom.spring.ioc.pojo.User;


public class Client {
	public static ApplicationContext context = null;
	
	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
		context = new ClassPathXmlApplicationContext("applicationContext-bean.xml");
		System.out.println("spring-ioc容器启动完成");
	}
	
	@Test
	public void test(){
		//默认为singleton,singleton在ioc容器启动时实例化
		//prototype在context.getBean("prototype")时实例化
		User default1 = (User) context.getBean("default");
		User default2 = (User) context.getBean("default");
		System.out.println("default == default: " + (default1 == default2));
		
		User singleton1 = (User) context.getBean("singleton");
		User singleton2 = (User) context.getBean("singleton");
		System.out.println("singleton == singleton: " + (singleton1 == singleton2));
		
		User prototype1 = (User) context.getBean("prototype");
		User prototype2 = (User) context.getBean("prototype");
		System.out.println("prototype == prototype: " + (prototype1 == prototype2));
	}
	
}
